package com.dongwu.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config implements EnvironmentAware {

	private RelaxedPropertyResolver propertyResolver;
	
	
	@Value("${dongwu.swagger.package}")
	private String pkg;
	@Value("${dongwu.swagger.title}")
	private String title;
	
	@Value("${dongwu.swagger.description}")
	private String description;
	@Value("${dongwu.swagger.contact}")
	private String contact;
	@Value("${dongwu.swagger.version}")
	private String version;

	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.basePackage(pkg))
				.paths(PathSelectors.any()).build();
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title(title)
				.description(description)
				.contact(contact).version(version)
				.build();
	}

	@Override
	public void setEnvironment(Environment environment) {

//		this.propertyResolver = new RelaxedPropertyResolver(environment, "dongwu.swagger.");

	}
}
